<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">




  <meta name="google-site-verification" content="A_78WZOvfJTnffhkbRiXvoT0JZXLHHpQQ1lN0GVkPBU">









  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.2.0" color="#222">






<link rel="stylesheet" href="/css/main.css?v=7.2.0">






<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">








<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.2.0',
    sidebar: {"position":"left","display":"always","offset":12,"onmobile":true},
    back2top: {"enable":true,"sidebar":true,"scrollpercent":true},
    copycode: {"enable":false,"show_result":false,"style":null},
    fancybox: false,
    mediumzoom: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="keywords" content="echototo666">
<meta property="og:type" content="website">
<meta property="og:title" content="echototo6666">
<meta property="og:url" content="http://www.echototo666.com/page/4/index.html">
<meta property="og:site_name" content="echototo6666">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="echototo6666">



  <link rel="alternate" href="/atom.xml" title="echototo6666" type="application/atom+xml">



  
  
  <link rel="canonical" href="http://www.echototo666.com/page/4/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  
  <title>echototo6666 - 站在巨人肩膀上，注定也要成为巨人的一部分</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">echototo6666</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">站在巨人肩膀上，注定也要成为巨人的一部分</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类<span class="badge">6</span></a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档<span class="badge">35</span></a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



</div>
    </header>

    
  
  

  

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dkeTMzMTY0NDc0MQ==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></span>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/04/28/laravel_bind/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/04/28/laravel_bind/" class="post-title-link" itemprop="url">Laravel中使用Ioc容器的singleton方法和bind方法创建实例的区别</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-04-28 23:00:34" itemprop="dateCreated datePublished" datetime="2018-04-28T23:00:34+00:00">2018-04-28</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>void bind(string|array $abstract, Closure|string|null $concrete = null, bool $shared = false)<br>void singleton(string|array $abstract, Closure|string|null $concrete = null)  等同于 bind($abstract,$concrete ,true)<br>void instance(string $abstract, mixed $instance)  绑定实例化对象</p>
</blockquote>
<p>Laravel 服务容器在使用时一般分为两个阶段：使用之前进行绑定（bind）完成将实现类绑定到接口；使用时对通过接口解析（make）出服务。<br>Laravel 内置多种不同的绑定方法以用于不同的使用场景。但无论哪种绑定方式，它们的最终目标是一致的：绑定接口到实现。<br>这样的好处是在项目的编码阶段建立起接口和实现的映射关系，到使用阶段通过抽象类（接口）解析出它的具体实现，这样就实现了项目中的解耦。</p>
<p>在 bind 方法中，主要完成以下几个方面的处理：</p>
<ul>
<li>干掉之前解析过的服务实例；</li>
<li>将绑定的实现类封装成闭包，以确保后续处理的统一；</li>
<li>针对已解析过的服务实例，再次触发重新绑定回调函数，同时将最新的实现类更新到接口里面。</li>
</ul>
<p>它们两个都是返回一个类的实例，不同的是singleton是单例模式，而bind是每次返回一个新的实例，看下面的两个例子。</p>
<ol>
<li>Ioc容器bind方法<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">require __DIR__.&apos;/../bootstrap/autoload.php&apos;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class tanteng</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">    public $name=&apos;init_str&apos;;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$container = new Illuminate\Container\Container();</span><br><span class="line"></span><br><span class="line">$container-&gt;bind(&apos;tanteng&apos;);</span><br><span class="line"></span><br><span class="line">$instance = $container-&gt;make(&apos;tanteng&apos;);</span><br><span class="line"></span><br><span class="line">$instance-&gt;name = &apos;tanteng&apos;;</span><br><span class="line"></span><br><span class="line">$instance2 = $container-&gt;make(&apos;tanteng&apos;);</span><br><span class="line"></span><br><span class="line">//$instance2-&gt;name = &apos;tuntun&apos;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo $instance-&gt;name.&apos; &apos;.$instance2-&gt;name;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<blockquote>
<p>输出的结果：<br>tanteng init_str</p>
</blockquote>
<p>结论：<br>通过bind方法创建实例不是单例模式，而是创建新的实例。</p>
<ol start="2">
<li>Ioc容器singleton方法<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">require __DIR__.&apos;/../bootstrap/autoload.php&apos;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class single</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">    public $value;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$container = new Illuminate\Container\Container();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$container-&gt;singleton(&apos;single&apos;);</span><br><span class="line"></span><br><span class="line">$instance3 = $container-&gt;make(&apos;single&apos;);</span><br><span class="line"></span><br><span class="line">$instance4 = $container-&gt;make(&apos;single&apos;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$instance3-&gt;value = &apos;aaaa&apos;;</span><br><span class="line"></span><br><span class="line">$instance4-&gt;value = &apos;bbbb&apos;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo $instance3-&gt;value.&apos; &apos;.$instance4-&gt;value;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<blockquote>
<p>输出结果：<br>bbbb bbbb</p>
</blockquote>
<p>结论：<br>使用singleton创建实例使用的是单例模式，每次返回同一个实例。<br>以上代码可以放在public下，如test.php运行。</p>
<p>再看框架底层代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">public function singleton($abstract, $concrete = null)</span><br><span class="line">&#123;</span><br><span class="line">    $this-&gt;bind($abstract, $concrete, true);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>发现singleton方法其实也是调用bind方法，只是最后一个参数是true，表示单例模式。框架源代码：Illuminate/Container/Container.php</p>
<p>附上bind()方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">public function bind($abstract, $concrete = null, $shared = false)</span><br><span class="line">    &#123;</span><br><span class="line">        $abstract = $this-&gt;normalize($abstract);</span><br><span class="line"></span><br><span class="line">        $concrete = $this-&gt;normalize($concrete);</span><br><span class="line"></span><br><span class="line">        // If the given types are actually an array, we will assume an alias is being</span><br><span class="line">        // defined and will grab this &quot;real&quot; abstract class name and register this</span><br><span class="line">        // alias with the container so that it can be used as a shortcut for it.</span><br><span class="line">        if (is_array($abstract)) &#123;</span><br><span class="line">            list($abstract, $alias) = $this-&gt;extractAlias($abstract);</span><br><span class="line"></span><br><span class="line">            $this-&gt;alias($abstract, $alias);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        // If no concrete type was given, we will simply set the concrete type to the</span><br><span class="line">        // abstract type. After that, the concrete type to be registered as shared</span><br><span class="line">        // without being forced to state their classes in both of the parameters.</span><br><span class="line">        $this-&gt;dropStaleInstances($abstract);</span><br><span class="line"></span><br><span class="line">        if (is_null($concrete)) &#123;</span><br><span class="line">            $concrete = $abstract;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        // If the factory is not a Closure, it means it is just a class name which is</span><br><span class="line">        // bound into this container to the abstract type and we will just wrap it</span><br><span class="line">        // up inside its own Closure to give us more convenience when extending.</span><br><span class="line">        if (! $concrete instanceof Closure) &#123;</span><br><span class="line">            $concrete = $this-&gt;getClosure($abstract, $concrete);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $this-&gt;bindings[$abstract] = compact(&apos;concrete&apos;, &apos;shared&apos;);</span><br><span class="line"></span><br><span class="line">        // If the abstract type was already resolved in this container we&apos;ll fire the</span><br><span class="line">        // rebound listener so that any objects which have already gotten resolved</span><br><span class="line">        // can have their copy of the object updated via the listener callbacks.</span><br><span class="line">        if ($this-&gt;resolved($abstract)) &#123;</span><br><span class="line">            $this-&gt;rebound($abstract);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/04/28/shell_group/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/04/28/shell_group/" class="post-title-link" itemprop="url">利用group 查找文件夹下包含‘key’的文件</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-04-28 23:00:34" itemprop="dateCreated datePublished" datetime="2018-04-28T23:00:34+00:00">2018-04-28</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/linux/" itemprop="url" rel="index"><span itemprop="name">linux</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">root@izhp36yfj8lo876bsm8f2nz api (master) # grep PARAMS_ERROR -rl --include=&quot;*.php&quot; ./</span><br><span class="line">./config/app.php</span><br><span class="line">./app/Exceptions/OmgException.php</span><br><span class="line">./app/Http/Controllers/ActivityController.php</span><br><span class="line">./app/Http/Controllers/MarkController.php</span><br><span class="line">./app/Http/Controllers/ImgManageController.php</span><br><span class="line">./app/Http/Controllers/RedeemController.php</span><br><span class="line">./app/Http/Controllers/AwardController.php</span><br><span class="line">./app/Http/Controllers/OneYuanController.php</span><br><span class="line">./app/Http/Controllers/ExamineController.php</span><br><span class="line">./app/Http/Controllers/MoneyShareController.php</span><br><span class="line">./app/Http/Controllers/IntegralMallController.php</span><br><span class="line">./app/Http/Controllers/ChannelController.php</span><br><span class="line">./app/Http/JsonRpcs/DaZhuanPanJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/NetworkDramaDzpJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/ActivityJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/ScratchJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/RobRateCouponJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/WorldCupJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/XjdbJsonrpc.php</span><br><span class="line">./app/Http/JsonRpcs/CollectCardJsonrpc.php</span><br><span class="line">root@izhp36yfj8lo876bsm8f2nz api (master) # sed -i s/PARAMS_ERROR/USER_PARAMS_ERROR/g &apos;grep PARAMS_ERROR -rl --include=&quot;*.php&quot; ./&apos;</span><br><span class="line">sed：无法读取 grep PARAMS_ERROR -rl --include=&quot;*.php&quot; ./：没有那个文件或目录</span><br><span class="line">root@izhp36yfj8lo876bsm8f2nz api (master) # sed -i s/PARAMS_ERROR/USER_PARAMS_ERROR/g `grep PARAMS_ERROR -rl --include=&quot;*.php&quot; ./`</span><br><span class="line">root@izhp36yfj8lo876bsm8f2nz api (master) # git status</span><br></pre></td></tr></table></figure>
<p>​​​​​​​​​​​​​​<br><img src="https://user-images.githubusercontent.com/9856659/51667733-97783280-1ffb-11e9-821c-4031fa1c3278.png" alt="image"></p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/04/28/PHPcode/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/04/28/PHPcode/" class="post-title-link" itemprop="url">PHPcode执行过程</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-04-28 23:00:34" itemprop="dateCreated datePublished" datetime="2018-04-28T23:00:34+00:00">2018-04-28</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ol>
<li>Scanning(Lexing) ,将PHP代码转换为语言片段(Tokens)</li>
<li>Parsing, 将Tokens转换成简单而有意义的表达式</li>
<li>Compilation, 将表达式编译成Opocdes</li>
<li>Execution, 顺次执行Opcodes，每次一条，从而实现PHP脚本的功能。</li>
</ol>
<blockquote>
<p>token_get_all(),这个函数就可以将一段PHP代码 Scanning成Tokens；</p>
</blockquote>
<h3 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">➜  wdy cat for.php</span><br><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">$tokens = token_get_all(&apos;&lt;?php echo 123;?&gt;&apos;);</span><br><span class="line">print_r($tokens);</span><br><span class="line"></span><br><span class="line">?&gt;</span><br><span class="line">➜  wdy php for.php</span><br><span class="line">Array</span><br><span class="line">(</span><br><span class="line">    [0] =&gt; Array</span><br><span class="line">        (</span><br><span class="line">            [0] =&gt; 374</span><br><span class="line">            [1] =&gt; &lt;?php</span><br><span class="line">            [2] =&gt; 1</span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">    [1] =&gt; Array</span><br><span class="line">        (</span><br><span class="line">            [0] =&gt; 317</span><br><span class="line">            [1] =&gt; echo</span><br><span class="line">            [2] =&gt; 1</span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">    [2] =&gt; Array</span><br></pre></td></tr></table></figure>
<h3 id="vld介绍"><a href="#vld介绍" class="headerlink" title="vld介绍"></a>vld介绍</h3><blockquote>
<p>vld是PECL（PHP 扩展和应用仓库）的一个PHP扩展，现在最新版本是 0.14.0（2016-12-18），它的作用是：显示转储PHP脚本（opcode）的内部表示（来自PECL的vld简介）。简单来说，可以查看PHP程序的opcode。</p>
</blockquote>
<h3 id="安装vld扩展"><a href="#安装vld扩展" class="headerlink" title="安装vld扩展"></a>安装vld扩展</h3><ol>
<li>下载官方插件压缩包<br><span class="exturl" data-url="aHR0cDovL3BlY2wucGhwLm5ldC9wYWNrYWdlL3ZsZA==" title="http://pecl.php.net/package/vld">http://pecl.php.net/package/vld<i class="fa fa-external-link"></i></span></li>
<li>安装</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># wget http://pecl.php.net/get/vld-0.14.0.tgz</span><br><span class="line"></span><br><span class="line"># tar zxvf vld-0.14.0.tgz</span><br><span class="line">root@wdy vld-0.14.0 # phpize</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Configuring for:<br>PHP Api Version:         20131106<br>Zend Module Api No:      20131226<br>Zend Extension Api No:   220131226</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># ./configure --with-php-config=/usr/local/php/bin/php-config</span><br><span class="line"># make &amp;&amp; make install</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Build complete.<br>Don’t forget to run ‘make test’.</p>
</blockquote>
<blockquote>
<p>Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"># vi /usr/local/php/etc/php.ini</span><br></pre></td></tr></table></figure>
<blockquote>
<p>extension = “vld.so”</p>
</blockquote>
<p><span class="exturl" data-url="aHR0cDovL3d3dy5waHAubmV0L21hbnVhbC96aC9pbnN0YWxsLnBlY2wucGhwLWNvbmZpZy5waHA=" title="http://www.php.net/manual/zh/install.pecl.php-config.php">php-config<i class="fa fa-external-link"></i></span></p>
<p>至此,VLD就安装完了。写个简单的测试文件</p>
<hr>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">root@wdy ~ # cat yield.php</span><br><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">function xrange($start,$end,$step = 1)&#123;</span><br><span class="line">	for($i = $start; $i&lt;=$end;$i += $step)&#123;</span><br><span class="line">		yield $i;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//foreach(xrange(1,1000000) as $num)&#123;</span><br><span class="line">//	echo $num,&quot;\n&quot;;</span><br><span class="line">//&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$range = xrange(1,1000000);</span><br><span class="line">var_dump($range);</span><br><span class="line">var_dump($range instanceof Iterator);</span><br><span class="line">?&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line">root@wdy ~ # php -dvld.active=1 yield.php</span><br><span class="line">Finding entry points</span><br><span class="line">Branch analysis from position: 0</span><br><span class="line">Jump found. (Code = 62) Position 1 = -2</span><br><span class="line">filename:       /root/yield.php</span><br><span class="line">function name:  (null) /*opcode所属函数。全局，此处为null。每个函数会有对应的完整的opcode信息。*/</span><br><span class="line">number of ops:  12 /*此段opcode有多少个运算操作*／</span><br><span class="line">compiled vars:  !0 = $range</span><br><span class="line">／*op list 核心部分 需要对照zend文档查看*／</span><br><span class="line">／*line 操作所在的行号*／</span><br><span class="line">／*#* 操作*／</span><br><span class="line">／*op 操作符 对应c的操作*／</span><br><span class="line">line     #* E I O op                           fetch          ext  return  operands</span><br><span class="line">-------------------------------------------------------------------------------------</span><br><span class="line">   3     0  E &gt;   NOP</span><br><span class="line">  14     1        SEND_VAL                                                 1</span><br><span class="line">         2        SEND_VAL                                                 1000000</span><br><span class="line">         3        DO_FCALL                                      2  $0      &apos;xrange&apos;</span><br><span class="line">         4        ASSIGN                                                   !0, $0</span><br><span class="line">  15     5        SEND_VAR                                                 !0</span><br><span class="line">         6        DO_FCALL                                      1          &apos;var_dump&apos;</span><br><span class="line">  16     7        FETCH_CLASS                                 128  :3      &apos;Iterator&apos;</span><br><span class="line">         8        INSTANCEOF                                       ~4      !0, $3</span><br><span class="line">         9        SEND_VAL                                                 ~4</span><br><span class="line">        10        DO_FCALL                                      1          &apos;var_dump&apos;</span><br><span class="line">  18    11      &gt; RETURN                                                   1</span><br><span class="line"></span><br><span class="line">branch: #  0; line:     3-   18; sop:     0; eop:    11; out1:  -2</span><br><span class="line">path #1: 0,</span><br><span class="line">Function xrange:</span><br><span class="line">Finding entry points</span><br><span class="line">Branch analysis from position: 0</span><br><span class="line">Jump found. (Code = 45) Position 1 = 10, Position 2 = 8</span><br><span class="line">Branch analysis from position: 10</span><br><span class="line">Jump found. (Code = 161) Position 1 = -2</span><br><span class="line">Branch analysis from position: 8</span><br><span class="line">Jump found. (Code = 42) Position 1 = 6</span><br><span class="line">Branch analysis from position: 6</span><br><span class="line">Jump found. (Code = 42) Position 1 = 4</span><br><span class="line">Branch analysis from position: 4</span><br><span class="line">filename:       /root/yield.php</span><br><span class="line">function name:  xrange</span><br><span class="line">number of ops:  11</span><br><span class="line">compiled vars:  !0 = $start, !1 = $end, !2 = $step, !3 = $i</span><br><span class="line">line     #* E I O op                           fetch          ext  return  operands</span><br><span class="line">-------------------------------------------------------------------------------------</span><br><span class="line">   3     0  E &gt;   RECV                                             !0</span><br><span class="line">         1        RECV                                             !1</span><br><span class="line">         2        RECV_INIT                                        !2      1</span><br><span class="line">   4     3        ASSIGN                                                   !3, !0</span><br><span class="line">         4    &gt;   IS_SMALLER_OR_EQUAL                              ~1      !3, !1</span><br><span class="line">         5      &gt; JMPZNZ                                        8          ~1, -&gt;10</span><br><span class="line">         6    &gt;   ASSIGN_ADD                                    0          !3, !2</span><br><span class="line">         7      &gt; JMP                                                      -&gt;4</span><br><span class="line">   5     8    &gt;   YIELD                                                    !3</span><br><span class="line">   6     9      &gt; JMP                                                      -&gt;6</span><br><span class="line">   7    10    &gt; &gt; GENERATOR_RETURN</span><br><span class="line"></span><br><span class="line">branch: #  0; line:     3-    4; sop:     0; eop:     3; out1:   4</span><br><span class="line">branch: #  4; line:     4-    4; sop:     4; eop:     5; out1:  10; out2:   8</span><br><span class="line">branch: #  6; line:     4-    4; sop:     6; eop:     7; out1:   4</span><br><span class="line">branch: #  8; line:     5-    6; sop:     8; eop:     9; out1:   6</span><br><span class="line">branch: # 10; line:     7-    7; sop:    10; eop:    10; out1:  -2</span><br><span class="line">path #1: 0, 4, 10,</span><br><span class="line">path #2: 0, 4, 8, 6, 4, 10,</span><br><span class="line">End of function xrange</span><br><span class="line"></span><br><span class="line">object(Generator)#1 (0) &#123;</span><br><span class="line">&#125;</span><br><span class="line">bool(true)</span><br></pre></td></tr></table></figure>
<h5 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h5><ul>
<li><p><span class="exturl" data-url="aHR0cDovL3d3dy5waHBwYW4uY29tLzIwMTEvMDUvdmxkLWV4dGVuc2lvbi8=" title="http://www.phppan.com/2011/05/vld-extension/">VLD扩展使用指南<i class="fa fa-external-link"></i></span></p>
</li>
<li><p><span class="exturl" data-url="aHR0cDovL3BocC5uZXQvbWFudWFsL3poL2ludGVybmFsczIub3Bjb2Rlcy5saXN0LnBocC8=" title="http://php.net/manual/zh/internals2.opcodes.list.php/">Zend Engine 2 操作码列表<i class="fa fa-external-link"></i></span></p>
</li>
</ul>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/04/28/git_chmod/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/04/28/git_chmod/" class="post-title-link" itemprop="url">忽略git文件权限</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-04-28 13:02:34" itemprop="dateCreated datePublished" datetime="2018-04-28T13:02:34+00:00">2018-04-28</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/linux/" itemprop="url" rel="index"><span itemprop="name">linux</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">root@wdy hq_passport (dev) # git status</span><br><span class="line"># 位于分支 dev</span><br><span class="line"># 尚未暂存以备提交的变更：</span><br><span class="line">#   （使用 &quot;git add &lt;file&gt;...&quot; 更新要提交的内容）</span><br><span class="line">#   （使用 &quot;git checkout -- &lt;file&gt;...&quot; 丢弃工作区的改动）</span><br><span class="line">#</span><br><span class="line">#	修改：      app/service/rpcserverimpl/operativerpcimpl.php</span><br><span class="line">#</span><br><span class="line">修改尚未加入提交（使用 &quot;git add&quot; 和/或 &quot;git commit -a&quot;）</span><br><span class="line">root@wdy hq_passport (dev) # git diff</span><br><span class="line">diff --git a/app/service/rpcserverimpl/operativerpcimpl.php b/app/service/rpcserverimpl/operativerpcimpl.php</span><br><span class="line">old mode 100644</span><br><span class="line">new mode 100755</span><br><span class="line">root@wdy hq_passport (dev) # git config core.filemode false</span><br><span class="line">root@wdy hq_passport (dev) # git status</span><br><span class="line"># 位于分支 dev</span><br><span class="line">无文件要提交，干净的工作区</span><br><span class="line">root@wdy hq_passport (dev) #</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git config core.filemode false  // 当前版本库</span><br><span class="line">$ git config --global core.fileMode false // 所有版本库</span><br></pre></td></tr></table></figure>
<p><img src="https://user-images.githubusercontent.com/9856659/51670305-54b95900-2001-11e9-9aa8-85ebb0c0ec0f.png" alt="image"></p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.echototo666.com/2018/04/27/predis_phpredis/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Lip">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://avatars0.githubusercontent.com/u/9856659">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="echototo6666">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                
                <a href="/2018/04/27/predis_phpredis/" class="post-title-link" itemprop="url">phpredis 和 predis</a>
              
            
          </h2>
        

        <div class="post-meta">
          

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-04-27 23:00:34" itemprop="dateCreated datePublished" datetime="2018-04-27T23:00:34+00:00">2018-04-27</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-03-24 02:40:06" itemprop="dateModified" datetime="2020-03-24T02:40:06+00:00">2020-03-24</time>
              </span>
            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="phpredis-和-predis"><a href="#phpredis-和-predis" class="headerlink" title="phpredis 和 predis"></a>phpredis 和 predis</h1><ol>
<li><p>phpredis 是使用c写的php扩展，predis 是使用纯php写的。<br>在性能上的区别当然是扩展更好一些，但其实这两个实现还有更大的区别，就是连接的保持。<br>phpredis在扩展中使用c可以保持php-fpm到redis的长连接，所以一个php-fpm进程上的多个请求是复用同一个连接的。phpredis的pconnect就是长连接方式。</p>
</li>
<li><p>predis是使用php的socket来连接redis，所以需要每次请求连接redis。<br>可以看出laravel的官方是推荐使用predis的，因为纯php实现的原因，只需要composer即可安装，非常符合laravel便捷的思想。</p>
</li>
</ol>
<p><strong>phpredis 和 predis 的性能差距没有跨数量级，当然要考虑具体业务，如果业务非常依赖redis，并且单机qps需要支持的比较大，建议使用phpredis。如果你只是使用laravel使用redis实现规模小的业务，建议不用改变predis。</strong></p>

          
        
      
    </div>

    

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/3/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/3/">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/">5</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/5/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <div class="site-overview-wrap sidebar-panel sidebar-panel-active">
        
       <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  
    <img class="site-author-image" itemprop="image" src="https://avatars0.githubusercontent.com/u/9856659" alt="Lip">
  
  <p class="site-author-name" itemprop="name">Lip</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>


  <nav class="site-state motion-element">
    
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">35</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>



  <div class="feed-link motion-element">
    <a href="/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>





  <div class="links-of-author motion-element">
    
      <span class="links-of-author-item">
      
      
      
        
      
        <a href="/13126666448" title="WeChat &rarr; 13126666448"><i class="fa fa-fw fa-wechat"></i></a>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dkeTMzMTY0NDc0MQ==" title="GitHub &rarr; https://github.com/wdy331644741"><i class="fa fa-fw fa-github"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="bWFpbHRvOjEzMDE1NTMxNzE3QDE2My5jb20=" title="E-Mail &rarr; mailto:13015531717@163.com"><i class="fa fa-fw fa-envelope"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly93ZWliby5jb20vZWNob3RvdG82NjY=" title="Weibo &rarr; https://weibo.com/echototo666"><i class="fa fa-fw fa-weibo"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly93d3cuZmFjZWJvb2suY29tL2VjaG90b3RvNjY2" title="FB Page &rarr; https://www.facebook.com/echototo666"><i class="fa fa-fw fa-facebook"></i></span>
      </span>
    
      <span class="links-of-author-item">
      
      
      
        
      
        <span class="exturl" data-url="aHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS91c2Vycy85OTY3MzcxL2Rvbmd5YW5nLXdhbmc=" title="StackOverflow &rarr; https://stackoverflow.com/users/9967371/dongyang-wang"><i class="fa fa-fw fa-stack-overflow"></i></span>
      </span>
    
  </div>







          
        </div>
        
        <script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
        <script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
        <div class="widget-wrap">
          <h3 class="widget-title">Tag Cloud</h3>
          <div id="myCanvasContainer" class="widget tagcloud">
            <canvas width="250" height="250" id="resCanvas" style="width=100%">
              <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/IoC/">IoC</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/api/">api</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/awk/">awk</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug/">debug</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/laravel/">laravel</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mac/">mac</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/">php</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/react/">react</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shell/">shell</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/webpack/">webpack</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/设计模式/">设计模式</a><span class="tag-list-count">1</span></li></ul>
            </canvas>
          </div>
        </div>
        
      </div>

      

      
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">  <span class="exturl" data-url="aHR0cDovL3d3dy5iZWlhbi5taWl0Lmdvdi5jbg==">echototo666 </span>&copy; 2017 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lip</span>

  

  
</div>











<div class="BbeiAn-info"">
  京ICP备 -
  <a href="http://beian.miit.gov.cn/">20007883号</a>
  
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>










  
  















  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




  <script src="/js/utils.js?v=7.2.0"></script>

  <script src="/js/motion.js?v=7.2.0"></script>



  
  


  <script src="/js/affix.js?v=7.2.0"></script>

  <script src="/js/schemes/pisces.js?v=7.2.0"></script>




  

  <script src="/js/next-boot.js?v=7.2.0"></script>

  

  
  <script src="/js/exturl.js?v=7.2.0"></script>


  

  

  

  

  

  

  



  




  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  




  



<script>
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME

window.addEventListener("message", function(e) {
  var data = e.data;
  if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) {
    var featureID = data.split(':')[1];
    var height = data.split(':')[2];
    $(`iframe[data-feature=${featureID}]`).height(parseInt(height) + 30);
  }
}, false);
</script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>


  

  


  

</body>
</html>
